package com.lefull.lefullbase.widget;


import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.lefull.lefullbase.R;

public class ImageToast extends Toast {
    private static ImageToast imageToast;
    private TextView textView;

    public ImageToast(Context context) {
        super(context);
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.toast_image, null);
        textView = (TextView) view.findViewById(R.id.toast_msg);
        setDuration(Toast.LENGTH_SHORT);
        setGravity(Gravity.CENTER, 0, 0);
        setView(view);
    }

    public ImageToast(Context context, String msg) {
        super(context);
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.toast_image, null);
        textView = (TextView) view.findViewById(R.id.toast_msg);
        textView.setText(msg);
        setDuration(Toast.LENGTH_SHORT);
        setGravity(Gravity.CENTER, 0, 0);
        setView(view);
    }

    public static ImageToast getInstance(Context context) {
        if (imageToast == null) {
            synchronized (ImageToast.class) {
                if (imageToast == null) {
                    imageToast = new ImageToast(context);
                }
            }
        }
        return imageToast;
    }

    public void setText(String msg) {
        if (textView != null) {
            textView.setText(msg);
        }
    }


}
